﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using Sbook.Data;

namespace Sbook.Data
{
    public class BannnerController : SqlDataProvider
    {
        #region[Banner_GetById]
        public List<BannerInfo> Banner_GetById(string Id)
        {
            List<Data.BannerInfo> list = new List<Data.BannerInfo>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Banner_GetById", GetConnection()))
            {
                Data.BannerInfo obj = new Data.BannerInfo();
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@BId", Id));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.BannerIDataReader(dr));
                    }
                    dr.Close();
                    //conn.Close();
                }
            }
            return list;
        }
        #endregion
        #region[Banner_GetByTop]
        public List<BannerInfo> Banner_GetByTop(string Top, string Where, string Order)
        {
            List<Data.BannerInfo> list = new List<Data.BannerInfo>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Banner_GetByTop", GetConnection()))
            {
                Data.BannerInfo obj = new Data.BannerInfo();
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Top", Top));
                dbCmd.Parameters.Add(new SqlParameter("@Where", Where));
                dbCmd.Parameters.Add(new SqlParameter("@Order", Order));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.BannerIDataReader(dr));
                    }
                    dr.Close();
                    //conn.Close();
                }
            }
            return list;
        }
        #endregion
        #region[Banner_GetByAll]
        public List<BannerInfo> Banner_GetByAll()
        {
            List<Data.BannerInfo> list = new List<Data.BannerInfo>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Banner_GetByAll", GetConnection()))
            {
                Data.BannerInfo obj = new Data.BannerInfo();
                dbCmd.CommandType = CommandType.StoredProcedure;
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.BannerIDataReader(dr));
                    }
                    dr.Close();
                    //conn.Close();
                }
            }
            return list;
        }
        #endregion
        #region[Banner_Paging]
        public List<BannerInfo> Banner_Paging(string CurentPage, string PageSize)
        {
            List<Data.BannerInfo> list = new List<Data.BannerInfo>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Banner_Paging", GetConnection()))
            {
                Data.BannerInfo obj = new Data.BannerInfo();
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@CurentPage", CurentPage));
                dbCmd.Parameters.Add(new SqlParameter("@PageSize", PageSize));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.BannerIDataReader(dr));
                    }
                    dr.Close();
                    //conn.Close();
                }
            }
            return list;
        }
        #endregion
        #region[Banner_Insert]
        public bool Banner_Insert(BannerInfo data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Banner_Insert", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@BLink", data.BLink));
                dbCmd.Parameters.Add(new SqlParameter("@BType", data.BType));
                dbCmd.Parameters.Add(new SqlParameter("@BStatus", data.BStatus));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("Banner");
            return true;
        }
        #endregion
        #region[Banner_Update]
        public bool Banner_Update(BannerInfo data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Banner_Update", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@BId", data.BId));
                dbCmd.Parameters.Add(new SqlParameter("@BLink", data.BLink));
                dbCmd.Parameters.Add(new SqlParameter("@BType", data.BType));
                dbCmd.Parameters.Add(new SqlParameter("@BStatus", data.BStatus));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("Banner");
            return true;
        }
        #endregion
        #region[Banner_Delete]
        public bool Banner_Delete(string Id)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Banner_Delete", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@BId", Id));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("Banner");
            return true;
        }
        #endregion

    }
}